package com.woniuxy.portal.controller;

import com.woniuxy.portal.model.vo.AddressVo;
import com.woniuxy.portal.service.AddressService;
import com.woniuxy.portal.utils.JwtUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2024-10-28
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RestController
@RequestMapping("address")
@Slf4j
public class AddressController {

    @Autowired
    private AddressService addressService;

    @Autowired
    private JwtUtil jwtUtil;

    /**
     * 通过用户id获取当前用户的收货地址
     */
    @GetMapping("/findAddress")
    @ApiOperation("获取当前用户的收货地址")
    public ResponseEntity<List<AddressVo>> findAddress(@RequestHeader(name = "Authorization", required = false) String token) {
        //获取当前登录用户的id
        String userId = jwtUtil.getValue(token, "userId");
        //获取当前用户的地址列表
        List<AddressVo> list = addressService.findByUserId(Long.parseLong(userId));
        return ResponseEntity.ok(list);
    }

}
